package com.zzyl.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;


    /**
     * 查询所有护理等级
     * @return
     */
    @Override
    public List<NursingLevelVo> listAll() {
      List<NursingLevelVo> vo = nursingLevelMapper.listAll();
      return vo;
    }

    @Override
    public void insert(NursingLevelDto nursingLevelDto) {
        NursingLevel bean = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        bean.setCreateTime(LocalDateTime.now());
        bean.setUpdateTime(LocalDateTime.now());
        bean.setUpdateBy(bean.getCreateBy());
        nursingLevelMapper.insert(bean);
    }



    @Override
    public PageResponse<NursingLevelVo> listByPage(String name, Integer status, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        Page<NursingLevelVo> vo= nursingLevelMapper.listByPage(name,status);
        return PageResponse.of(vo,NursingLevelVo.class);
    }

    @Override
    public NursingLevelVo getById(Integer id) {
        NursingLevelVo vo =  nursingLevelMapper.getById(id);

        return  vo;
    }

    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel bean = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        bean.setUpdateTime(LocalDateTime.now());
        bean.setUpdateBy(bean.getCreateBy());
        nursingLevelMapper.update(bean);
    }

    @Override
    public void deleteById(Integer id) {
        nursingLevelMapper.deleteById(id);
    }
}
